﻿using System;
using System.Windows.Forms;

namespace Sistema.WF.Componentes.Controles
{
    public class R2MaskedTextBox : MaskedTextBox
    {
        public R2Configuracoes _conf = new R2Configuracoes();

        public R2MaskedTextBox()
        {
            BackColor = System.Drawing.Color.White;
            this.DefinirMascara();
        }

        #region Cores

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            this.BackColor = _conf.OnFocus();
        }
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            this.BackColor = _conf.LostFocus();
        }
        #endregion
        
        #region Mascara
        private void DefinirMascara()
        {
            switch (this._Mascara)
            {
                case enumMascara.TELEFONE:
                    base.Mask = "(99)9999-9999";
                    break;
                case enumMascara.CPF:
                    base.Mask = "999,999,999-99";
                    break;
                case enumMascara.CNPJ:
                    base.Mask = "99,999,999/9999-99";
                    break;
                case enumMascara.CEP:
                    base.Mask = "99,999-999";
                    break;
                case enumMascara.RG:
                    base.Mask = "99,999,999-9";
                    break;
            }
        }
        
        private enumMascara _Mascara = enumMascara.CPF;
        public enumMascara Mascara
        {
            get
            {
                return _Mascara;
            }
            set
            {
                _Mascara = value;
                DefinirMascara();
            }
        }
#endregion


    }
    
    public enum enumMascara
    {
        CEP,
        CPF,
        CNPJ,
        TELEFONE,
        RG
    }
}
